<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="ID">
      </el-table-column>
      <el-table-column
        prop="title"
        label="名称">
      </el-table-column>
      <el-table-column
        prop="file_type"
        label="文件类型">
      </el-table-column>
      <el-table-column
        prop="size"
        label="大小(kb)">
      </el-table-column>
      <el-table-column
        prop="operator"
        label="发布人">
      </el-table-column>
      <el-table-column
        prop="create_time"
        label="发布时间">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-download"
            @click="sourcesDownload(scope.row)">
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>
<script>
import {saveAs} from 'file-saver'
import {sourcePage} from "@/api/sources";

export default {
  name: 'index',
  data() {
    return {
      tableData: [],
      currentPage: 1,
      pageSizes: [5, 10, 15, 20],
      pageSize: 5,
      total: 0
    }
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val
      this.sourcePageData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.sourcePageData()
    },
    sourcePageData() {
      sourcePage({page: this.currentPage, size: this.pageSize})
        .then(response => {
          this.total = response.data.total
          this.tableData = response.data.tableData
        })
    },
    async sourcesDownload(row) {
      const response = await fetch('http://sxiz096fj.hd-bkt.clouddn.com/' + row.key);
      const blob = await response.blob();
      saveAs(blob, row.key);
    }
  },
  created() {
    this.sourcePageData()
  }
}
</script>
<style scoped lang="scss">


</style>

>
